$(function () {


    $('#qdate').datetimepicker({
        //viewMode: 'day',
        format: 'YYYY-MM-DD'
    });
    $('#ddate').datetimepicker({
        format: 'YYYY-MM-DD',
        useCurrent: false //Important! See issue #1075
    });
    $("#qdate").on("dp.change", function (e) {
        $('#ddate').data("DateTimePicker").minDate(e.date);
    });
    $("#ddate").on("dp.change", function (e) {
        $('#qdate').data("DateTimePicker").maxDate(e.date);
    });


    $('#table').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../house/list',
        columns: [
            {
                field: 'id',
                title: 'id',
                visible : false,
            },{
                field: 'doornumber',
                title: '房屋门牌号'
            }, {
                field: 'typeb.id',
                title: '房屋状态',
                formatter: function (value, row, index) {
                    if (row.typeb.id == 1) {
                        return "空闲";
                    }else {
                        return "已售";
                    }
                }

            },{
                field: 'userdetails.name',
                title: '姓名',
                // visible : false,
            },
            {
                field: 'userdetails.phone',
                title: '手机号',
                // visible : false,
            },{
                field: 'userdetails.sfz',
                title: '身份证号码',
                // visible : false,
            },{
                field: 'userdetails.property.name',
                title: '产权',
                // visible : false,
            },
            {
                field: 'sale.name',
                title: '楼'
            }, {
                field: 'danyuan.name',
                title: '单元'
            }, {
                field: 'floor',
                title: '层数'
            }, {
                field: 'huxing.name',
                title: '户型'
            }, {
                field: 'direction.name',
                title: '房屋朝向'
            }, {
                field: 'measure',
                title: '平米',
                formatter: function (value, row, index) {
                    var jia = row .measure+"平方米";
                    return jia;
                }
            },{
                field:'remark',
                title:'简介'
            }],
        contentType:"application/x-www-form-urlencoded",
        queryParamsType: '',
        height: 700,
        pageNumber: 1,
        pageSize: 15,
        pagination:true,
        queryParams: queryParams,
        sidePagination:'server',
        onDblClickRow: function (row, $element, field) {
            $("#myModal3").modal("hide")
            $("#name").val(row.doornumber)
            $("#phone").val(row.userdetails.phone)
        },
    });
    $('#Stable').bootstrapTable({
        url: '${pageContext.request.contextPath}/../../car/Qttt',
        columns: [{
            field:"id",
            title:"id",
            visible : false,
        },{
            field: 'carid',
            title: '车位编号'
        },{
            field: 'type',
            title: '当前状态',
            formatter:function (value,row,index) {
                if (row.type==1){
                    return "空闲";
                }else if(row.type==2) {
                    return "已售";
                }else if(row.type==3){
                    return "已租";
                }else if(row.type==4){
                    return "临时停车";
                }
            }
        },{
            field:'ymoney',
            title:'预售价格',

        },{
            field: 'name',
            title: '使用人',

        },{
            field:'carnumber',
            title:'车牌号',

        },{
            field : 'phone',
            title : '手机号',

        },{
            field: 'qdate',
            title: '起始日期',

        },{
            field: 'ddate',
            title: '到期时间',

        },{
            field: 'address',
            title: '用户地址',

        },{
            field:'remark',
            title:'备注',

        },{
            field : 'xx',
            title : '操作',
            formatter:function(value,row,index){
                return "<a href='javascript:del("+row.id+")'>删除</a>" ;
            }
        }],
        contentType : "application/x-www-form-urlencoded",
        queryParamsType:'',
        height:680,
        pageList:[5,10,15],
        queryParams: SqueryParams,
        pageNumber:1,
        pageSize:15,
        pagination:true,
        sidePagination:'server',
        onDblClickRow: function (row, $element, field) {
            $("#myModal2").modal("show");
            $("#bianhao").val(row.carid)
            $("#yin1").val(row.id);
            $("#name").val(row.name);
            $("#carnumber").val(row.carnumber)
            $("#phone").val(row.phone);
            $("#qdate").val(row.qdate);
            $("#ddate").val(row.ddate);
            $("#type").val(row.type);
            $("#Symoney").val(row.ymoney)
            $("#address").val(row.address)
            $("#remark").val(row.remark)

        },

    });
})
function xiugai() {
    var opt = $("#Stable").bootstrapTable('getOptions');
    var bianhao=$("#bianhao").val();
    var id=$("#yin1").val();
    var name = $("#name").val();
    var carnumber = $("#carnumber").val();
    var phone=$("#phone").val();
    var qdate = $("#qdate").val();
    var ddate=$("#ddate").val();
    var type=$("#type").val();
    var ymoney=$("#Symoney").val();
    var address=$("#address").val();
    var remark=$("#remark").val();
    $.post("${pageContext.request.contextPath}/../../car/Qss",{"carid":bianhao,"id":id,"type":type,"ymoney":ymoney,"name":name,"carnumber":carnumber,"phone":phone,"qdate":qdate,"ddate":ddate,"address":address,"remark":remark,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
        $("#Stable").bootstrapTable("load",data);
    })
}

//增加车位
function add() {
    var opt = $("#Stable").bootstrapTable('getOptions');
    var Scarid = $("#Scarid").val();
    var ymoney = $("#ymoney").val();
    var type=1;
    $.post("${pageContext.request.contextPath}/../../car/Qtianjia",{"type":type,"carid":Scarid,"ymoney":ymoney,"pageNumber":opt.pageNumber,"pageSize":opt.pageSize},function (data) {
        $("#Stable").bootstrapTable("load",data);
    })
}

//删除
function del(id) {
    var id=id;
    var opt = $("#table").bootstrapTable('getOptions');
    $.post("${pageContext.requ`est.contextPath}/../../car/Qdel",{"id":id,"pageNumber":opt.pageNumber,"pageSize":15},function (data) {
        $("#Stable").bootstrapTable("load",data);
    })
}

//打开模态框
function shuji() {
    $("#myModal3").modal("show");
}

//按条件查询
function ban(){
    var opt = $("#table").bootstrapTable('getOptions') ;
    var type = $("#zhuangtai").val();
    var carid = $("#carid").val();
    $.post('${pageContext.request.contextPath}/../../car/Qttt',{'pageNumber':opt.pageNumber,'pageSize':opt.pageSize,'type':type,'carid':carid},function(data){
        //重新给table绑定数据5
        $("#Stable").bootstrapTable("load",data) ;
    }) ;

}

//Stable查询
function SqueryParams(params) {
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'type':$("#zhuangtai").val(),
        'carid':$("#carid").val(),
    };
    return temp;
};

//table查询
function search() {
    var opt = $("#table").bootstrapTable('getOptions');

    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var men=$("#men").val();
    $.post('${pageContext.request.contextPath}/../../house/list', {
        'shu':shu,
        'number':men,
        'type':2,
        'pageSize': opt.pageSize,
        'pageNumber': 1
    }, function (data) {

        //重新给table绑定数据
        $("#table").bootstrapTable("load", data);
    });
}

//table查询
function queryParams(params) {
    var shu ;
    var node = $('#tt').tree('getSelected');
    if (node){
        var s = node.text;
        if (node.attributes){
            s += ","+node.attributes.p1+","+node.attributes.p2;
        }
        shu = s;
    }
    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        'pageSize': params.pageSize,  //页面大小
        'pageNumber': params.pageNumber, //页码
        'shu':shu,
        'number':$("#men").val(),
        'type':2,
    };
    return temp;
};

